package com.may.entity;

import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @program: dubbo-nacos
 * @description:
 * @author: Bobby.Ma
 * @create: 2020-08-23 12:09
 **/
@Data
@Accessors(chain = true)
@Entity
@Table(name = "user")
public class User implements Serializable {
    private static final long serialVersionUID = 8399248315322454169L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String uname;
    private Integer age;
    private Integer gender;
    private Date createTime;
    private Date updateTime;

    @OneToOne(fetch = FetchType.EAGER)
    //name属性指本实体中用来关联的字段，referencedColumnName指关联表的连接字段，不指定时默认为主键
    @JoinColumn(name = "info_id",referencedColumnName = "id")
    //当关联的表中无数据时返回null，而不是报错
    @NotFound(action= NotFoundAction.IGNORE)
    private UserInfo userInfo;
}
